package com.zs.toolbox.web2j.auth.utils;

import com.zs.toolbox.web2j.auth.contants.WtSecurityConstant;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.List;

/**
 * @author shuai.zhang  on 2018/9/21
 * @description
 */
public class WtTokenUtils {
     public static String createrToken(String id, List<String> auths, Date expireTime) {
        String token = Jwts.builder()
                .setExpiration(expireTime)
                .signWith(SignatureAlgorithm.HS512, WtSecurityConstant.TokenSerect)
                .setSubject(id + "-" + String.join(",",auths))
                .compact();
        return token;
    }

    public static String parseToken(String token) {
        String decodeUserInfo = Jwts.parser()
                .setSigningKey(WtSecurityConstant.TokenSerect)
                .parseClaimsJws(token)
                .getBody()
                .getSubject();
        return decodeUserInfo;
    }
}
